﻿@* Generator: Template
    GeneratePrettyNames : true *@
@functions{
    public NFinal.Compile.SqlTemplate.Model.QueryAll Model { get; set; }
}
#region	var @{@Model.varName};选取所有记录
			@if(Model.hasGenericType){
			if(Model.isDeclaration){
			@:List<@{@Model.type}> @{@Model.varName}=new List<@{@Model.type}>();
			}
			}else{
			@:var @{@Model.varName} = new List<__@{@Model.functionName}_@{@Model.varName}__>();
            }
			var __@{@Model.functionName}_@{@Model.varName}_command__ = new System.Data.SqlClient.SqlCommand("@{@Model.sql}", @{@Model.connectionVarName});
			@if(Model.isTransaction){
			@:__@{@Model.functionName}_@{@Model.varName}_command__.Transaction=@{@Model.transactionVarName};
			}
			@if(Model.sqlVarParameters.Count>0){
			@:var __@{@Model.functionName}_@{@Model.varName}_parameters__=new System.Data.SqlClient.SqlParameter[@{@Model.sqlVarParameters.Count}];
			}
			@{int i=0;}
			@foreach(var sqlVarParameter in Model.sqlVarParameters){
				if(sqlVarParameter.field!=null){
					if(sqlVarParameter.field.length>0){
					@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i] = new System.Data.SqlClient.SqlParameter("@@@{@sqlVarParameter.name}",System.Data.SqlDbType.@{@sqlVarParameter.field.dbType},@{@sqlVarParameter.field.length});
					@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i].Value = @{@sqlVarParameter.csharpName};
					}else{
					@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i] = new System.Data.SqlClient.SqlParameter("@@@{@sqlVarParameter.name}",System.Data.SqlDbType.@{@sqlVarParameter.field.dbType});
					@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i].Value = @{@sqlVarParameter.csharpName};
					}
				}else{
					@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i] = new System.Data.SqlClient.SqlParameter(":@{@sqlVarParameter.name}",@{@sqlVarParameter.name});
				}
				i++;
			}
			@if(Model.sqlVarParameters.Count>0){
			@:__@{@Model.functionName}_@{@Model.varName}_command__.Parameters.AddRange(__@{@Model.functionName}_@{@Model.varName}_parameters__);
			}
			var __@{@Model.functionName}_@{@Model.varName}_reader__= __@{@Model.functionName}_@{@Model.varName}_command__.ExecuteReader();
			if (__@{@Model.functionName}_@{@Model.varName}_reader__.HasRows)
			{
				while (__@{@Model.functionName}_@{@Model.varName}_reader__.Read())
				{
					@if(Model.hasGenericType){
					@:var __@{@Model.functionName}_@{@Model.varName}_temp__ = new @{@Model.type}();
					}else{
					@:var __@{@Model.functionName}_@{@Model.varName}_temp__ = new __@{@Model.functionName}_@{@Model.varName}__();
					}
					@{i=0;}
					@foreach(var field in Model.fields){
					if(field.isValueType){
					@:if(!__@{@Model.functionName}_@{@Model.varName}_reader__.IsDBNull(@i)){__@{@Model.functionName}_@{@Model.varName}_temp__.@{@field.structFieldName} =@{@field.GetMethodConvert} __@{@Model.functionName}_@{@Model.varName}_reader__.@{@field.GetMethodName}(@i)@{@field.GetMethodValue};}
					}else{
					@:__@{@Model.functionName}_@{@Model.varName}_temp__.@{@field.structFieldName} =@{@field.GetMethodConvert} __@{@Model.functionName}_@{@Model.varName}_reader__.@{@field.GetMethodName}(@i)@{@field.GetMethodValue};
					}
					i++;
					}
					@{@Model.varName}.Add(__@{@Model.functionName}_@{@Model.varName}_temp__);
				}
			}
			__@{@Model.functionName}_@{@Model.varName}_reader__.Dispose();
			__@{@Model.functionName}_@{@Model.varName}_command__.Dispose();
			#endregion
			